#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN=5e4+10;
LL n,c,a[MAXN],sum[MAXN],f[MAXN],q[MAXN];
double slope(LL x,LL y)
{
	return (f[x]-f[y]+sum[x]*sum[x]-sum[y]*sum[y])*1.0/(sum[x]-sum[y]);
}
int main()
{
	scanf("%lld%lld",&n,&c);++c;
	for(LL i=1;i<=n;++i)scanf("%lld",&a[i]);
	for(LL i=1;i<=n;++i)sum[i]=sum[i-1]+a[i];
	for(LL i=1;i<=n;++i)sum[i]+=i;
	LL l=0,r=0;
	for(LL i=1;i<=n;++i)
	{
		while(l<r&&slope(q[l],q[l+1])<=2*(sum[i]-c))++l;
		LL t=q[l];
		f[i]=f[t]+(sum[i]-sum[t]-c)*(sum[i]-sum[t]-c);
		while(l<r&&slope(q[r],i)<slope(q[r-1],q[r]))--r;
		q[++r]=i;
	}
	printf("%lld\n",f[n]);
	return 0;
}
